import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:ost_flutter_module/common/adapt.dart';
import 'package:ost_flutter_module/common/color.dart';
import 'package:ost_flutter_module/common/styles.dart';
import 'package:ost_flutter_module/common/utils.dart';
import 'package:ost_flutter_module/widget/custom_widget/custome_divider.dart';
import 'package:ost_flutter_module/widget/custom_widget/text_button.dart';

/// 顶部 取消 确定按钮样式
gShowBottomSheet(BuildContext context,
    {Widget child,
    String text,
    bool showCancel = true,
    bool showDone = true,
    VoidCallback cancel,
    ValueChanged<dynamic> done}) {
  showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(Adapt.px(Utils.padding)),
        topRight: Radius.circular(Adapt.px(Utils.padding)),
      ),
    ),
    builder: (context) => Container(
      padding: MediaQuery.of(context).viewInsets,
      constraints: BoxConstraints(
        maxHeight: ScreenUtil.getScreenH(context) * 2 / 3,
      ),
      child: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            _buildActions(
                text: text,
                showCancel: showCancel,
                showDone: showDone,
                cancel: () {
                  Navigator.pop(context);
                  cancel();
                },
                done: (value) {
                  done(value);
                }),
            child,
          ],
        ),
      ),
    ),
  );
}

Widget _buildActions(
        {String text,
        bool showCancel,
        bool showDone,
        VoidCallback cancel,
        ValueChanged<dynamic> done}) =>
    Column(
      children: [
        ButtonBar(
          buttonPadding: EdgeInsets.zero,
          alignment: MainAxisAlignment.spaceBetween,
          children: [
            GTextButton(
              title: showCancel ? '取消' : '',
              onPressed: showCancel ? cancel : null,
            ),
            Center(
              child: Text(
                text ?? '',
                style: TextStyles.payDownTimeTitleStyle,
              ),
            ),
            GTextButton(
              title: showDone ? '确定' : '',
              normalForgroundColor: color2A51A1,
              onPressed: showDone ? () => done('') : null,
            ),
          ],
        ),
        GDivider(indent: 0, endIndent: 0),
      ],
    );

/// 底部取消按钮样式
gShowCancelBottomSheet(
  BuildContext context, {
  Widget child,
  String text,
  bool showCancel = true,
  VoidCallback cancel,
}) {
  showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(Adapt.px(Utils.padding)),
        topRight: Radius.circular(Adapt.px(Utils.padding)),
      ),
    ),
    builder: (context) => Container(
      padding: MediaQuery.of(context).viewInsets,
      constraints: BoxConstraints(
        maxHeight: ScreenUtil.getScreenH(context) * 2 / 3,
      ),
      child: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            child,
            Center(
              child: Container(
                width: double.infinity,
                height: Adapt.px(50),
                child: GTextButton(
                  title: text ?? '取消',
                  fontSize: 16,
                  normalForgroundColor: color999999,
                  onPressed: () {
                    cancel();
                  },
                ),
              ),
            ),
            SizedBox(height: Adapt.px(24)),
          ],
        ),
      ),
    ),
  );
}
